home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmBrainDead
- Caption = "Brain Dead SMTP Example"
- ClientHeight = 5700
- ClientLeft = 885
- ClientTop = 840
- ClientWidth = 7680
- Height = 6105
- Icon = "brainded.frx":0000
- Left = 825
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 5700
- ScaleWidth = 7680
- Top = 495
- Width = 7800
- Begin VB.TextBox txtSubject
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 420
- Left = 1935
- TabIndex = 10
- Top = 1800
- Width = 5595
- End
- Begin VB.TextBox txtTo
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 420
- Left = 1935
- TabIndex = 8
- Top = 1260
- Width = 3750
- End
- Begin VB.TextBox txtFrom
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 420
- Left = 1935
- TabIndex = 6
- Top = 720
- Width = 3750
- End
- Begin VB.TextBox txtServer
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 420
- Left = 1935
- TabIndex = 3
- Top = 180
- Width = 3750
- End
- Begin VB.TextBox Text1
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 3120
- Left = 135
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 2
- Top = 2430
- Width = 7440
- End
- Begin VB.CommandButton btnSend
- Caption = "&Send"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 735
- Left = 5985
- TabIndex = 1
- Top = 180
- Width = 1545
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Caption = "Subject:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 300
- Index = 3
- Left = 90
- TabIndex = 9
- Top = 1845
- Width = 1785
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Caption = "To:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 300
- Index = 2
- Left = 90
- TabIndex = 7
- Top = 1305
- Width = 1785
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Caption = "From:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 300
- Index = 1
- Left = 90
- TabIndex = 5
- Top = 765
- Width = 1785
- End
- Begin VB.Label Label1
- Alignment = 1 'Right Justify
- Caption = "SMTP Gateway:"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 400
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 300
- Index = 0
- Left = 90
- TabIndex = 4
- Top = 225
- Width = 1770
- End
- Begin dsSocketLib.dsSocket DSSocket1
- Height = 420
- Left = 6885
- TabIndex = 0
- Top = 1125
- Width = 420
- _version = 65542
- _extentx = 741
- _extenty = 741
- _stockprops = 64
- localport = 0
- remotehost = ""
- remoteport = 0
- servicename = ""
- remotedotaddr = ""
- linger = -1 'True
- timeout = 10
- linemode = 0 'False
- eolchar = 10
- bindconnect = 0 'False
- sockettype = 0
- End
- Attribute VB_Name = "frmBrainDead"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- '---------------------------------------------------
- 'BRAINDED.FRM
- 'Copyright 1996 by Carl Franklin
- 'Unauthorized reproduction in any medium of this
- 'source code is strictly prohibited without written
- 'permission from the author and John Wiley & Sons.
- '---------------------------------------------------
- Dim nConnected As Integer
- Const SOCK_ACTION_CONNECT = 2
- Const SOCK_ACTION_CLOSE = 1
- Private Sub btnSend_Click()
- '-- Temporarily disable the button
- Screen.MousePointer = vbHourglass
- btnSend.Enabled = False
- '-- SMTP uses port 25
- DSSocket1.RemotePort = 25
- '-- Is this a DOT address?
- If IsDotAddress(Text1) Then
- '-- Yes. Use the RemoteDotAddr property
- DSSocket1.RemoteDotAddr = txtServer
- Else
- '-- No. Use the RemoteHost property
- DSSocket1.RemoteHost = txtServer
- End If
- '-- Try to connect
- nConnected = False
- On Error Resume Next
- DSSocket1.Action = SOCK_ACTION_CONNECT
- If Err Then
- '-- Error!
- MsgBox Error, vbInformation
- Else
- '-- Wait until we've connected
- Do
- DoEvents
- Loop Until nConnected
- '-- Send the email
- SendBrainDead DSSocket1, (txtFrom), (txtTo), (txtSubject), (Text1)
- '-- Close the port and beep as an indicator
- DSSocket1.Action = SOCK_ACTION_CLOSE
- Beep
- End If
- '-- Re-enable stuff
- Screen.MousePointer = vbNormal
- btnSend.Enabled = True
- End Sub
- Function IsDotAddress(szAddress As String) As Integer
- '-- This function determines if a string is an IP address like
- ' 199.200.199.120 or not
- Dim nPos As Integer
- Dim nIndex As Integer
- Dim szSection As String
- Dim szTemp As String
- szTemp = szAddress
- szAddress = Trim$(szAddress)
- For nIndex = 1 To 3
- nPos = InStr(szAddress, ".")
- If nPos Then
- szSection = Left$(szAddress, nPos - 1)
- If Len(szSection) = 0 Then
- Exit Function
- ElseIf Trim$(Str$(Val(szSection))) <> szSection Then
- Exit Function
- ElseIf Val(szSection) > 255 Then
- Exit Function
- ElseIf Val(szSection) < 0 Then
- Exit Function
- End If
- szAddress = Mid$(szAddress, nPos + 1)
- Else
- Exit Function
- End If
- Next
- If Len(szAddress) = 0 Then
- Exit Function
- ElseIf Trim$(Str$(Val(szAddress))) <> szAddress Then
- Exit Function
- ElseIf Val(szAddress) > 255 Then
- Exit Function
- ElseIf Val(szAddress) < 0 Then
- Exit Function
- End If
- szAddress = szTemp
- IsDotAddress = True
- End Function
- Private Sub DSSocket1_Connect()
- nConnected = True
- End Sub
- Sub SendBrainDead(DSSock As Control, szFrom As String, szTo As String, szSubject As String, szMsg As String)
- '-- This routine sends an email message via an SMTP gateway.
- Dim szCRLF As String
- Dim szCompleteMsg As String
- '-- All lines end with a CR/LF Pair
- szCRLF = Chr$(13) & Chr$(10)
- szCompleteMsg = "MAIL FROM: <" & szFrom & ">" & szCRLF _
- & "RCPT TO: <" & szTo & ">" & szCRLF _
- & "DATA" & szCRLF _
- & "DATE: " & Format$(Now, "dd mmm yy ttttt") & szCRLF _
- & "FROM: " & szFrom & szCRLF _
- & "TO: " & szTo & szCRLF _
- & "SUBJECT: " & szSubject & szCRLF & szCRLF _
- & szMsg & szCRLF & "." & szCRLF
- DSSock.Send = szCompleteMsg
- End Sub
-